package org.giovanolli.mumi.view.datamodel;

import java.io.Serializable;
import java.util.List;

import javax.faces.model.ListDataModel;

import org.giovanolli.mumi.entities.IdentificableEntity;
import org.primefaces.model.SelectableDataModel;

public class SelectionDataModel<T extends IdentificableEntity> extends ListDataModel<T> implements Serializable, SelectableDataModel<T> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7507683002006936635L;

	public SelectionDataModel() {
	}

	public SelectionDataModel(List<T> data) {
		super(data);
	}

	@Override
	public T getRowData(String rowKey) {
		List<T> objs = (List<T>) getWrappedData();

		for (T obj : objs) {
			if (obj.getUid().equals(rowKey))
				return obj;
		}

		return null;
	}

	@Override
	public Object getRowKey(T object) {
		return object.getUid();
	}

}
